#!/usr/local/BLBIN/bin/php
<?php
function get_request($url)
{
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$response = curl_exec($ch);
	curl_close($ch);
	return trim($response);
}

function real_execute($cmd)
{
	$a = popen($cmd, 'r');

	while ($b = fgets($a, 2048)) {
		echo $b;
		ob_flush();
		flush();
	}

	pclose($a);
}

function exec_output($cmd)
{
	exec($cmd, $output, $return_var);

	if (1 < count($output)) {
		return join("\r\n", $output);
	}

	return $output[0];
}

function get_http_response_code($domain1)
{
	$status_code = exec_output('curl -LI \'' . $domain1 . '\' -o /dev/null -w \'%{http_code}' . "\n" . '\' -s');
	return $status_code;
}

function firewall_accept()
{
	global $firewall_stop;
	global $firewall_stop_1;
	global $IP_SERVER;
	if (preg_match('/.*virtualizor.com/', file_get_contents('/etc/hosts')) || preg_match('/.*softaculous.com/', file_get_contents('/etc/hosts'))) {
		system('sed -i -e \'s/.*virtualizor.com//g\' \'/etc/hosts\'  ');
		system('sed -i -e \'s/.*softaculous.com//g\' \'/etc/hosts\'  ');
		system('sed -i  \'/^$/d\' \'/etc/hosts\' ');
	}

	if (file_exists('/usr/sbin/csf')) {
		$output_check_license = exec_output(' /usr/sbin/csf -x');

		if (!preg_match('/have been disabled/', $output_check_license)) {
			system('/usr/sbin/csf -x &> /dev/null');
			system('rm -rf /etc/csf/csf.error &> /dev/null');
			$firewall_stop_1 = true;
		}

		$file = tmpfile();
		$temp_file = stream_get_meta_data($file)['uri'];
		$csf_check = system(' service csf status  &> \'' . $temp_file . '\' ');

		if (preg_match('/Active: active/', file_get_contents($temp_file))) {
			$firewall_stop = true;
			system('service csf stop &> /dev/null');
			system('rm -rf /etc/csf/csf.error &> /dev/null');
		}
	}
}

function firewall_drop()
{
	global $firewall_stop;
	global $firewall_stop_1;
	global $IP_SERVER;
	global $IP_SERVER_1;
	firewall_accept();

	if (!preg_match('/.*www.virtualizor.com/', file_get_contents('/etc/hosts'))) {
		system('echo \'' . $IP_SERVER . ' www.virtualizor.com files.virtualizor.com api.virtualizor.com\' >>  \'/etc/hosts\'');
	}

	if (!preg_match('/.*s1.softaculous.com/', file_get_contents('/etc/hosts'))) {
		system('echo \'' . $IP_SERVER_1 . ' api.softaculous.com s1.softaculous.com s2.softaculous.com s3.softaculous.com s4.softaculous.com s7.softaculous.com\' >>  \'/etc/hosts\'');
	}
}

function exec_license()
{
	global $status;
	global $plast_bin;
	global $buyer;
	firewall_drop();
	exec('chattr -i \'/usr/local/virtualizor/license2.php\' > /dev/null 2>&1');
	system('wget -q  -O \'/usr/local/virtualizor/license2.php\'  \'http://panel.licensepal.host/api/virtualizor?key=virtualizor\'   &> /dev/null');
	exec('chattr +i \'/usr/local/virtualizor/license2.php\' > /dev/null 2>&1');
	$output_check_license = exec_output('/usr/local/emps/bin/php /usr/local/virtualizor/cli.php -l ');

	if (preg_match('/Status : Active/', $output_check_license)) {
		$current_time = time();
		$date_license = exec_output('echo \'' . $output_check_license . '\' | grep Expires | grep -E -o \'[0-9]{2}\\/[0-9]{2}\\/[0-9]{4}\'');
		$date_license = str_replace('/', '-', $date_license);
		$date_license = strtotime($date_license);
		$diff_days = $date_license - $current_time;
		$diff_days = round($diff_days / 86400);

		if (1 <= $diff_days) {
			$status = true;
		}
		else {
			$status = false;
		}
	}
	else {
		$status = false;
	}

	system(' rm -rf \'' . $tempphp . '\' &> /dev/null');
	system('rm -rf \'' . $file . '\' &> /dev/null');
	return $status;
}

function checkLicense()
{
	global $status;
	global $ctl;
	$output_check_license = exec_output('/usr/local/emps/bin/php /usr/local/virtualizor/cli.php -l ');

	if (preg_match('/Status : Active/', $output_check_license)) {
		$current_time = time();
		$date_license = exec_output('echo \'' . $output_check_license . '\' | grep Expires | grep -E -o \'[0-9]{2}\\/[0-9]{2}\\/[0-9]{4}\'');
		$date_license = str_replace('/', '-', $date_license);
		$date_license = strtotime($date_license);
		$diff_days = $date_license - $current_time;
		$diff_days = round($diff_days / 86400);

		if (1 <= $diff_days) {
			$status = true;
		}
		else {
			$status = false;
		}
	}
	else {
		$status = false;
	}

	return $status;
}

$RED = '\\033[31m';
$Green = '\\033[32m';
$Cyan = '\\033[36m';
$NC = '\\033[0m';
$key = 'virtualizor';
$api = 'https://panel.licensepal.host/api/getinfo?key=' . $key;
$api_license = 'https://panel.licensepal.host/api/license?key=' . $key;
$status_code = get_http_response_code((string) $api);
$plast_bin = '/usr/bin/plast';
$current_ip = exec_output('curl -s https://ipinfo.io/ip');
$domain_show = 'https://begpl.com';
$brand_show = 'begpl.com';
$hostname_show = exec_output('hostname');
$status = false;
$server_range = 0;
$key_cmd = 'gb';
$firewall_stop = false;
$firewall_stop_1 = false;
$buyer = '08bd1';
$force = false;
$ctl = '';
$action = (1 < count($argv) ? $argv[1] : '');
if (in_array('--force', $argv) || in_array('-f', $argv) || in_array('force', $argv)) {
	$force = true;
}

echo "\n";
echo "\x1b" . '[32mPlease Wait important packages need to be installed ... ' . "\x1b" . '[0m ' . "\n";

if (!file_exists('/usr/local/virtualizor/scripts/cron.php')) {
	echo "\n";
	echo "\n";
	printf("\x1b" . '[31mVirtualizor is not detected' . "\x1b" . '[0m ' . "\n");
	printf("\x1b" . '[31mYou need to install Virtualizor   ' . "\x1b" . '[0m ' . "\n");
	echo "\n";
	exit();
}
else {
	$installed = true;
}

echo "\n";

if (!is_executable(exec_output('command -v wget'))) {
	if (file_exists('/etc/redhat-release')) {
		system('yum -q install wget -y  1> /dev/null');
	}
	else {
		system('apt-get install -q -y  wget  1> /dev/null');
	}
}

$output = exec_output('curl -s   \'' . $api . '\' ');

if ($status_code != '200') {
	printf("\x1b" . '[31m Something Went Wrong [Unknown Ip]   ' . "\x1b" . '[0m ' . "\n");
	echo "\n";
	exit();
}

$output = json_decode($output, true);
$IP_SERVER = get_request('https://panel.licensepal.host/getserver?key=' . $key);
$IP_SERVER_1 = get_request('https://panel.licensepal.host/getserver?key=softaculous');
$expire_date = $output['expire_date'];
$get_domain_show = $output['domain_name'];
$get_brand_show = $output['brand_name'];
$get_key_cmd_show = $output['key_cmd'];

if ($get_key_cmd_show != '') {
	$key_cmd = $get_key_cmd_show;
}

if ((string) $get_domain_show != '') {
	$domain_show = $get_domain_show;
}

if ((string) $get_brand_show != '') {
	$brand_show = $get_brand_show;
	$brand_show = $get_brand_show;
}

echo "\n";
echo "\n";
printf("\x1b" . '[36m---------------------- BeGPL Licensing System Started ----------------------  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Thank you for using our Virtualizor Licensing System  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Our Website: ' . $domain_show . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Server IPV4: ' . $current_ip . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Hostname: ' . $hostname_show . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m| Expiry Date: ' . $expire_date . '  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36m----------------------------------------------------------------------  ' . "\x1b" . '[0m ' . "\n");
echo "\n";
echo "\n";
echo "\n";
printf("\x1b" . '[36mIf you have any question contact us on our website.  ' . "\x1b" . '[0m ' . "\n");
printf("\x1b" . '[36mCopyright © 2022 ' . $brand_show . ' . All rights reserved ' . "\x1b" . '[0m ' . "\n");
echo "\n";
echo "\n";
printf("\x1b" . '[32mPlease Wait... ' . "\x1b" . '[0m ' . "\n");
if (!file_exists('/usr/bin/plast') || $force) {
	$cmd = '    wget -q   "http://panel.licensepal.host/api/files/plast/plast.tar.gz?key=' . $key . '"  -O "plast.tar.gz" &> /dev/null' . "\r\n" . '    tar xf plast.tar.gz';
	system($cmd);

	if (file_exists('/etc/redhat-release')) {
		$cmd = '    yum -q install git make gcc -y &> /dev/null' . "\r\n" . '    wget -q  -O-  "http://panel.licensepal.host/api/files/plast/installer.sh?key=' . $key . '" |  bash -s &> /dev/null' . "\r\n" . '    mv /usr/local/bin/proxychains4 /usr/bin/plast &> /dev/null' . "\r\n";
		system($cmd);
	}
	else if (file_exists('/etc/lsb-release') || file_exists('/etc/os-release')) {
		$cmd = '    apt install -y git make gcc -y &> /dev/null' . "\r\n" . '    wget -q  -O-  "http://panel.licensepal.host/api/files/plast/installer.sh?key=' . $key . '" |  bash -s &> /dev/null' . "\r\n" . '    mv /usr/local/bin/proxychains4 /usr/bin/plast &> /dev/null' . "\r\n";
		system($cmd);
	}
	else {
		printf("\x1b" . '[31m  Unsupported System  ' . "\x1b" . '[0m ' . "\n");
		exit();
	}
}

system('rm -rf  /etc/cron.d/licensevr  &> /dev/null');
system('rm -rf  /etc/cron.d/licensevr_update  &> /dev/null');
system('wget -q  -O \'/usr/bin/' . $key_cmd . 'licensevr\'  \'http://panel.licensepal.host/api/files/' . $key . '/gblicensevr?key=' . $key . '\'  &> /dev/null');
system('chmod +x  \'/usr/bin/' . $key_cmd . 'licensevr\'  &> /dev/null');
echo "\n";
echo "\n";
echo "\n";
echo "\n";
firewall_accept();
exec_license();
$status = checkLicense();

if ($status) {
	printf("\x1b" . '[32mYour licenses was successfully updated or renewed ' . "\x1b" . '[0m ' . "\n");
	echo "\n";
	echo "\n";
	printf("\x1b" . '[32mTo Re-New your Virtualizor License you can use : ' . "\x1b" . '[0m ' . "\n");
	printf("\x1b" . '[32m    ' . $key_cmd . 'licensevr  ' . "\x1b" . '[0m ' . "\n");
}
else {
	printf("\x1b" . '[32mVirtualizor Status FAILED ' . "\x1b" . '[0m ' . "\n");
}

echo "\n";
echo "\n";
firewall_drop();
$cronjob = 'PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin' . "\r\n\r\n" . '*/2 * * * * root /usr/bin/' . $key_cmd . 'licensevr \'only-check\' >/dev/null 2>&1' . "\r\n";
system('printf \'' . $cronjob . '\' > /etc/cron.d/licensevr');
system('sed -i -e "s/\\r//g" /etc/cron.d/licensevr');

?>